/**
 * 
 */
package niuke.xiaohongshu;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @author zhongfang
 *
 */
public class t2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] == 0) {
				a[i] = -1;
			}
		}
		sc.close();
		HashMap<Integer, int[]> map = new HashMap<>();
		int curSum = 0;
		map.put(0, new int[] { -1, -1 });
		for (int i = 0; i < n; i++) {
			curSum += a[i];
			if (map.containsKey(curSum)) {
				map.get(curSum)[1] = i;
			} else {
				int[] t = new int[] { i, -1 };
				map.put(curSum, t);
			}
		}
		int maxLen = 0;
		for (int[] array : map.values()) {
			if (array[1] != 0) {
				maxLen = Math.max(maxLen, array[1] - array[0]);
			}
		}
		System.out.println(maxLen);
	}

}
